//
//  NetworkTool.m
//  网络工具类
//
//  Created by 吴俊杰 on 2016/11/13.
//  Copyright © 2016年 吴俊杰. All rights reserved.
//

#import "NetworkTool.h"

@implementation NetworkTool

+ (instancetype)sharedNetworkTool{
    static NetworkTool *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[NetworkTool alloc] init];
    });
    return instance;
}

- (void)GETWithURLString:(NSString *)URLString parameters:(id)parameters success:(void (^)(id))successBlock failure:(void (^)(NSError *))failureBlock{
    
    [[AFHTTPSessionManager manager] GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failureBlock(error);
    }];
}

- (void)POSTWithURLString:(NSString *)URLString parameters:(id)parameters success:(void (^)(id))successBlock failure:(void (^)(NSError *))failureBlock{
    
    [[AFHTTPSessionManager manager] POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        successBlock(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failureBlock(error);
    }];
}

@end
